package com.ysd.modules.sys.service.impl;

import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.utils.PageUtils;
import com.ysd.modules.sys.dao.SysClassesDao;
import com.ysd.modules.sys.dao.SysStudentDao;
import com.ysd.modules.sys.entity.SysClassesEntity;
import com.ysd.modules.sys.entity.SysStudent;
import com.ysd.modules.sys.service.SysClassesService;
import com.ysd.modules.sys.service.SysStudentService;
@Service
public class SysStudentServiceImpl  extends ServiceImpl<SysStudentDao, SysStudent> implements SysStudentService{
	   @Autowired
	   private SysStudentDao sysStudentDao;
	
	
	  /**
     * 根据班级名分页查询班级
     *
     * @param searchName
     * @param page
     * @param limit
     * @return
     */
	@Override
	public PageUtils getAllStudents(String sid,String cid,String searchName, Integer page, Integer limit) {
		// TODO Auto-generated method stub
		  Page<SysStudent> pageInfo = new Page<>(page, limit);
	        QueryWrapper<SysStudent> wapper = new QueryWrapper<>();
	        if (!TextUtils.isEmpty(searchName)) {
	            wapper.like("name", searchName);	            
	        }
	        if(!TextUtils.isEmpty(sid)) {
	        	wapper.eq("school_id", Integer.parseInt(sid));
	        }
	        if(!TextUtils.isEmpty(cid)) {
	        	wapper.eq("class_id", Integer.parseInt(cid));
	        }
	        return new PageUtils(sysStudentDao.selectPage(pageInfo, wapper));
	}
	 /**
     * 添加学生
     *
     * @param sysStudent
     * @return
     */

	@Override
	public int addStudents(SysStudent sysStudent) {
		// TODO Auto-generated method stub
		  return sysStudentDao.insert(sysStudent);
	}
	 /**
     * 修改学信息
     *
     * @param sysStudent
     * @return
     */

	@Override
	public int updateStudents(SysStudent sysStudent) {
		// TODO Auto-generated method stub
		return sysStudentDao.updateById(sysStudent);
	}
	 /**
     * 删除学生
     *
     * @param id
     * @return
     */
	@Override
	public int delStudents(Integer id) {
		// TODO Auto-generated method stub
		 return sysStudentDao.deleteById(id);
	}

}
